/*
 *
 *  Copyright (C) 2009 GSyC/LibreSoft
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Author : Roberto Calvo Palomino <rocapal@gsyc.es>
 *
 */

package com.LibreGeoSocial.App.Resources;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Point;
import android.location.Location;

import com.LibreGeoSocial.App.AR.Overlays.DrawResource;
import com.LibreGeoSocial.App.Utils.LocationUtils;

public class ResourceItem {

	public static final int MILLION = 1000000;


	private String mTitle;
	private String mSummary;
	private String mDate;
	private Double mLatitude;
	private Double mLongitude;
	private Double mAltitude;
	private String mUrl;
	private String mService;
	
	private ArrayList<String> mKeywords;
	private Point mLocation = null;
	
	private DrawResource drawn;
	private boolean isloaded = false;
	private Location mLoc = null;

	public ResourceItem () {
		super();
	}
	
	public ResourceItem(String title, String summary, String date,
			Double latitude, Double longitude, Double altitude, 
			String url, String service, ArrayList<String> keywords) {
		super();
		mTitle = title;
		
		if (summary==null)
			mSummary = "Without Description.";
		else
			mSummary = summary;
		
		mDate = date;
		mLatitude = latitude;
		mLongitude = longitude;
		mAltitude = altitude;
		mUrl = url;
		mService = service;
		mKeywords = keywords;
		
		mLocation = new Point (mLatitude.intValue(), mLongitude.intValue());

		mLoc = new Location ("gps");
		mLoc.setLatitude(latitude);
		mLoc.setLongitude(longitude);
		
	}
	
	public String getTitle() {
		return mTitle;
	}
	public String getSummary() {
		return mSummary;
	}
	public String getDate() {
		return mDate;
	}
	public Double getLatitude() {
		return mLatitude;
	}
	public Double getLongitude() {
		return mLongitude;
	}
	public Double getAltitude(){
		return mAltitude;
	}
	public String getUrl() {
		return mUrl;
	}
	public String getService() {
		return mService;
	}
	public ArrayList<String> getKeywords() {
		return mKeywords;
	}
	
	public Point getLocation() {
		return mLocation;
	}
	
	public DrawResource getDrawn(){
		return drawn;
	}
	
	public boolean isLoaded(){
		return isloaded;
	}
	
	public void setLoaded(boolean isloaded){
		this.isloaded = isloaded;
	}
	
	public void setDrawnValues(float azimuth, float elevation, float distance){
		drawn.setValues(azimuth, elevation, distance);
	}
	
	public void createDrawn(Context context, String name){
		this.drawn = new DrawResource(context, name, null);
	}
	
	public void bringDrawnToFront(){
		drawn.bringToFront();
	}
	
	public void drawDistance(boolean draw){
		drawn.drawDistance(draw);
	}
	
	public void invalidateDrawn(){
		drawn.invalidate();
	}
	
	public float distanceToResource(float[] source){
		float d;
		
		Location sLocation = new Location ("gps");
		sLocation.setLatitude(source[0]);
		sLocation.setLongitude(source[1]);
		
		d = sLocation.distanceTo(mLoc);
		
		return d;
	}
	
	public float azimuthToResource(float source[]){
		float azimuth, resource[] = new float[2];
		
		resource[0] = (float) mLoc.getLatitude();
		resource[1] = (float) mLoc.getLongitude();
		
		azimuth = LocationUtils.calculateResourceAzimuth(source, resource);
		
		return azimuth;
	}
	
	public float rollToResource(float distance){
		float roll;
		
		roll = LocationUtils.calculateRoll(distance, (float)(double)mAltitude);
		
		return roll;
	}
	

	
}
